package day07;

import java.util.Random;

/**
 *
 * 生成4位验证码（大写字母，小写字母，数字）
 */
public class VerificationCode {
    public static void main(String[] args) {
        String code = generateVeriCode(4);
        System.out.println("验证码wobuhaowui：" + code);
    }

    /**
     * 生成验证码
     */
    public static String generateVeriCode(int len) {
        String code = "";
        char[] chs = {'a', 'b'};
        Random rand = new Random();
        for (int i = 1; i<=len;i++){
            int index = (int) (Math.random() * chs.length);
            code += chs[index]; //获取随机字符并拼接到code中
        }

        return code;
    }
}
